﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class ProfessionalDal
    {
        DBHepler helper = new DBHepler();

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <param name="proId"></param>
        /// <returns></returns>
        public bool Exists(string proId)
        {
            SqlParameter[] parameters ={
                                        new SqlParameter("@proId",proId)
                                      };
            int result = Int32.Parse(helper.GetExecuteScalar("sp_ExistsProfessional", parameters));
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 查询出所有的专业
        /// </summary>
        /// <returns></returns>
        public DataTable  GetAllProfessional()
        {
            return helper.GetDataTableByProc("sp_GetAllProfessional");
            
        }

        /// <summary>
        /// 增加专业信息
        /// </summary>
        /// <param name="professional"></param>
        /// <returns></returns>
        public bool AddProfessional(Model.Professional professional)
        {
            SqlParameter[] parameters = {
                                            new SqlParameter("@proId",professional.proId),
                                            new SqlParameter("@proName",professional.proName),
                                            new SqlParameter("@proDescribe",professional.proDescribe),
                                            new SqlParameter("@proNum",professional.proNum)
                                        };
            if (helper.InsertByProc("sp_AddProfessional", parameters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 修改更新专业信息
        /// </summary>
        /// <param name="professional"></param>
        /// <returns></returns>
        public bool UpdateProfessional(Model.Professional professional)
        {
            SqlParameter[] parameters = {
                                            new SqlParameter("@proId",professional.proId),
                                            new SqlParameter("@proName",professional.proName),
                                            new SqlParameter("@proDescribe",professional.proDescribe),
                                            new SqlParameter("@proNum",professional.proNum)
                                        };
            if (helper.UpdateByProc("sp_UpdateProfessional", parameters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除专业信息
        /// </summary>
        /// <param name="proId"></param>
        /// <returns></returns>
        public bool DelProfessional(string proId)
        {
            SqlParameter[] pamaeters = {
                                        new SqlParameter("@proId",proId)
                                       };
            if (helper.DeleteByProc("sp_DelProfessional", pamaeters) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 根据专业编号返回专业的信息
        /// </summary>
        /// <param name="proId"></param>
        /// <returns></returns>
        public DataTable GetProById(string proId)
        {
            SqlParameter[] parameters ={
                                        new SqlParameter("@proId",proId)
                                      };
            return helper.GetDataTableByProc("sp_GetProById", parameters);
        }
    }
}
